<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"
    import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>場地設備處理</title>
</head>
<body>
<% if(session.getAttribute("access") == "y" ){%>
<jsp:useBean id="mydb" scope="page" class="bean.ConDbBean"/> <%//連結資料庫的bean %>
<jsp:useBean id="p_state" scope="page" class="bean.StateBean"/>
<jsp:useBean id="pclass" scope="page" class="myclass.P_Class"/>
	<table width="800" border="0">
  		<tr>
    		<td>
    			<jsp:include page="test.jsp" flush="true" ></jsp:include></td> <%//include左選單 %>

    		<td>
    		<%--內頁--%>
    		<% 
	  		String sql="select * from FACILITY";
	  		ResultSet rs=mydb.executeQuery(sql); 
			sql="select COUNT(F_ID) from FACILITY"; //算total筆數
	  		ResultSet rs3=mydb.executeQuery(sql); 
	  		rs3.next();
			int nTotal=java.lang.Integer.valueOf(rs3.getString(""));
	  		%>
	  		
	  		<table>
        		<tr>
        			<td><a href="addFacility.jsp" target="_self" class="style2">新增設備資料</a></td>
        		</tr>
        	</table> 
        <% 
	  		if(nTotal==0){
			%>
    			
	  			<table width="600" border="0" bordercolor="#999999">
      				<tr>
      					<td>資料庫裡尚未儲存資料</td>
      				</tr>
      			</table>
      	 	<%
	  		}
	  		else
	  		{
			%>
	  			<table width="600" border="0">
	  				<tr>
    				<td><form id="form1" name="form1" method="post" action="do_delFacility.jsp">
      					<table width="100%" border="1">
      						<tr>
          						<td>設備編號</td>
          						<td>設備類別</td>
          						<td>設備名稱</td>
          						<td>狀態</td>
          						<td>修改</td>
          						<td><input type="submit" name="Submit" value="刪除" /></td>
        					</tr>
<%
	  						while(rs.next()){ //一行行讀資料,直至rs.next()為null則停止
	  							sql="select * from FACILITY_CLASS WHERE FC_ID='"+rs.getString("F_Class")+"'";
        						ResultSet rs2=pclass.getPcName(sql);
          						rs2.next();
%>
        					<tr>
          						<td><a href="detailFacility.jsp?id=<%=rs.getString("F_ID")%>" target="_black" class="style2"><%=rs.getString("F_ID")%></a></td>
          						<td><%=rs2.getString("FC_NAME")%></td>
          						<td><%=rs.getString("F_NAME")%></td>
          						<td><%=p_state.getPState(rs.getString("F_STATE"))%></td>
          						<td><a href="alter_Facility.jsp?fid=<%=rs.getString("F_ID")%>" target="_self" class="style2">修改</a></td>
          						<td><input name="del" type="checkbox" value="<%=rs.getString("F_ID")%>" /></td>
        					</tr>
<%
	  						}
%>
	  					</table>
<%    		
			}
 %>
 
    </form>
		</td>
  		</tr>
	</table>
    </td>
  </tr>
</table>
<%
  }
  else{
  	response.sendRedirect("../index.jsp"); //若沒有登入則回到index.jsp
  } 
  %>
</body>
</html>